#ifndef __MODS_MANAGER_H__
#define __MODS_MANAGER_H__

#include <cstdint>
#include <string>
#include <vector>
#include <map>
#include "Game/ModInfo.hpp"
#include "SimpleSingleton.hpp"

namespace PocketSurvival
{
    class Client;

    struct ModsInfo
    {
        std::vector<std::string> md5Values;
        std::string name;
        std::string packageName;
        std::string verison;

        friend inline void to_json(nlohmann::json &json, const ModsInfo &info);
        friend inline void from_json(const nlohmann::json &json, ModsInfo &info);
    };

    inline void to_json(nlohmann::json &json, const ModsInfo &info)
    {
        json = {{"Md5Values",info.md5Values},{"Name",info.name},{"PackageName",info.packageName},{"Verison",info.verison}};
    }
    inline void from_json(const nlohmann::json &json, ModsInfo &info)
    {
        info.md5Values      = json["Md5Values"].get<std::vector<std::string>>();
        info.name           = json["Name"].get<std::string>();
        info.packageName    = json["PackageName"].get<std::string>();
        info.verison        = json["Verison"].get<std::string>();
    }


    class ModsManager : public SimpleSingletonItem
    {
        friend class SimpleSingleton;

    private:
        // 是否需要校验mod，不需要校验则带mod也能进入
        bool m_mustVerigyMod;

        // 必须安装的mod，在需要校验的情况下，缺一个就不能进入服务器
        std::map<std::string, ModsInfo> m_mustBeInstalledModMap;
        
        // 允许使用的mod，装与不装都能进入服务器
        std::map<std::string, ModsInfo> m_allowedToUseModMap;

    private:
        ModsManager();
        ~ModsManager();
        ModsManager(const ModsManager &) = delete;
        ModsManager(ModsManager &&) = delete;
        ModsManager &operator=(const ModsManager &) = delete;
        ModsManager &operator=(ModsManager &&) = delete;

    public:
        bool verifyMods(const std::vector<ModInfo> &modInfos);
        void load();
        void save();
    };

} // namespace PocketSurvival


#endif
